var app = getApp();
import { averageUser, dealers } from '../../utils/tabBarUrl';
var util = require('../../utils/util.js');
var iv=null;
var encryptedData=null;
var shangpinPage;  //存放本页面的信息
var mySuperShop;
var mySuperFirstShop;
var left_height;//左侧滚动高度
var coll_right_h; //收藏滚动高度
var z_scroH;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    step:-1,
    template_id:0,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),  //微信版本是否过低
    loginInfo:null,  //门店基本信息
    rightDatas: [],  //供应商列表
    page:1,     //当前页码
    load: "加载中...",
    load_num:1,
    loading:1,
    ishide:false,
    gun:false, //scroll-view是否可以滚动
    searSuperName:'', //搜索供应商名称
    isShowSuperList:0 //0初始 1显示单个供应商组件（good_detail）2显示供应商列表  3显示库（good_manage）
  },
  // 去供应商列表页面
  toSuper:function(){
    wx.navigateTo({
      url: '/super_space/pages/supper/supper'
    });
  },
  // 添加供应商
  toAddSuper:function(){
    wx.navigateTo({
      url:'../wo/gongyingshangguanli/addgongyingshang/addgongyingshang'
    });
  },
  // 继承模板库
  tomobanku:function(){
    wx.navigateTo({
      url: 'mobanku/mobanku'
    });
  },
  // 进入体验号
  test_ck:function(){
    app.globalData.test=1; //进入体验号
    this.user_onLoad();
  },
  // 退出体验号
  toExit(){
    this.setData({
      step:-1,  //回到初始，避免app.globalData.openid没来及修改
      test:0
    });
    app.globalData.step=-1;
    app.globalData.test = 0; //退出体验账号
    app.globalData.list=[];
    this.getTabBar().setData({
      list:[]
    })
    this.user_onLoad();
  },
  // 去简明教程页面
  easytestck(){
    wx.navigateTo({
      url: 'steptest/steptest'
    })
  },
  // 点击供应商列表进入供应商页面
  itemClick(event) {
    var index = event.currentTarget.dataset.id;
    var id = this.data.rightDatas[index].id;
    if(this.data.rightDatas[index].status!=1){
      this.setData({
        is_cancel_apply:true,
        apply_super_name:this.data.rightDatas[index].company_name,
        copper_id:this.data.rightDatas[index].coop_id
      });
      return;
    };
    wx.navigateTo({
      url:'/pages/shangpin/shangpindetail/super_shop_details/super_shop_details?id='+ id+"&super_info="+JSON.stringify(this.data.rightDatas[index])+'&step='+this.data.step
    })
  },
  // 关闭取申弹窗
  close_apply:function(){
    this.setData({
      is_cancel_apply:false
    });
  },
  // 取消申请供应商
  conf_noapply:function(){
    var that = this;
    wx.showModal({
      title: '提示',
      content: '请确认取消申请',
      success: function (res) {
        if (res.confirm) {
          app.AppHttp('api/Client/del_cooper', {
            id: that.data.copper_id
          }, function (res) {
            console.log(JSON.stringify(res.data));
            that.setData({
              is_cancel_apply:false
            });
            that.getSupplierList(app.globalData.openid);
            wx.showToast({
              title:res.data.msg
            });
          });
        }
      }
    })
  },
  // 进入指定门店
  in_cur_door:function(){
    var sao_super=this.data.sao_super;
    var super_info={'logo':sao_super.logo,'company_name':sao_super.company_name,'status':1};
    wx.navigateTo({
      url:'/pages/shangpin/shangpindetail/super_shop_details/super_shop_details?id='+ sao_super.id+"&super_info="+JSON.stringify(super_info)+'&step='+this.data.step+'&type='+'sao'
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(options){   
    var that = this;  
    if(options){
      that.setData({
        type:options.type,
        share_super_id:options.id,
      }); 
    };
    z_scroH=0.2*wx.getSystemInfoSync().windowHeight-app.globalData.Capsule-app.globalData.Capsulehei;
    that.setData({
      phonetype:app.globalData.phonetype,
      CustomBar:app.globalData.CustomBar,
      Capsule:app.globalData.Capsule,
      Capsulehei:app.globalData.Capsulehei,
      CapsuleWid:app.globalData.CapsuleWid,
      z_scroH:z_scroH,
      call_load:1   //表示调用了onload
    }); 
    const pages = getCurrentPages();    //获取当前页面信息栈
    shangpinPage = pages[pages.length - 1]; //获取上一个页面信息  
    app.globalData.shangpinPage=shangpinPage;
    const query = wx.createSelectorQuery();
        query.select('.gouwuche_pos').boundingClientRect();
        query.select('.right_top_pos_in').boundingClientRect();
        query.exec((res) => {
        left_height=res[0].top-res[1].top;//左侧滚动高度
        coll_right_h=res[0].bottom-res[1].bottom;
        that.setData({
            left_height:left_height,
            coll_right_h:coll_right_h
        });
        z_scroH=0.2*wx.getSystemInfoSync().windowHeight-app.globalData.Capsule-app.globalData.Capsulehei;
        mySuperShop=this.selectComponent('#mySuperShop');
        mySuperFirstShop=that.selectComponent('#mySuperFirstShop');
        this.user_onLoad(); 
    });
  },
  user_onLoad: function () {
    var that = this; 
    var step;
    wx.request({
      url: 'https://www.xiaobangcai.com/get_appid_secret/xd',
      method: 'GET',
      data: {},
      success: function(res) {
        app.globalData.appId=res.data.appId;
        app.globalData.secret=res.data.secret;
        wx.login({
          success: function (res) {
            console.log(res.code);
            app.AppHttp("api/Client/getClientOpenId", {
              appId: app.globalData.appId,
              secret: app.globalData.secret,
              code: res.code
            }, function (res) {
              if (app.globalData.test == 1){     //体验号openid
                app.globalData.t_openid = res.data.openid;
                app.globalData.openid = 'oEZjr4gNtRs5dvc6btpnuAQKGO40';
              } else if (app.globalData.test == 0) { //正常用户openid
                app.globalData.session_key = res.data.session_key;
                app.globalData.openid = res.data.openid;
                // app.globalData.openid = 'oEZjr4l-db0rTL3Eylmk4D9BBym4'; //商贸
                // app.globalData.openid='oEZjr4kBhEimnqIIKzUAMZ26Odtw' //川（西电）
                // app.globalData.openid='oEZjr4sSZpSWAE-7NfwMK5UTF5cM';  //李
                // app.globalData.openid='oEZjr4pX4j9FxtZfTSlN4oNHz3kU'; //东府
                if (res.data.unionid != undefined) {
                  that.setData({
                    isunionid: res.data.unionid
                  });
                  app.globalData.unionid = res.data.unionid;
                } else {
                  that.setData({
                    isunionid: "emp"
                  });
                }
              };
              that.setData({
                test: app.globalData.test
              }); 
              app.AppHttp("api/Client/whetherAuth", { openid: app.globalData.openid, unionid: res.data.unionid}, function (res) {
                console.log(res);
                if (res.data.status == 1) {
                  console.log(res.data.data.unionid);
                  if(res.data.data.unionid==undefined && app.globalData.test==0){      
                    // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
                    wx.getUserInfo({
                      success: res => {
                        // 可以将 res 发送给后台解码出 unionId
                        console.log(res);
                        encryptedData=res.encryptedData;
                        iv=res.iv;
                        app.globalData.userInfo = res.userInfo
                        // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
                        // 所以此处加入 callback 以防止这种情况
                        var sdata = {
                          appId: app.globalData.appId,
                          sessionKey:app.globalData.session_key,
                          encryptedData:encryptedData,
                          iv:iv
                        };
                        app.AppHttp('api/Client/DataDecryption',sdata, function (res) {
                          console.log(JSON.stringify(res.data));
                            app.globalData.unionid = res.data.unionId;
                            app.AppHttp('api/Client/updateUnionid',{openid:app.globalData.openid,unionid:res.data.unionId}, function (res) {
                              console.log(JSON.stringify(res.data));  
                            });           
                        });
                      }
                    });
                  };
                  step=1;
                  app.AppHttp('api/Client/personalBasic', {
                    openid: app.globalData.openid
                  }, function (res) {
                    console.log(JSON.stringify(res.data));
                    app.globalData.person_id = res.data.data.id;   //用户个人id
                  });
                  app.AppHttp("api/Client/basicInfo", { openid: app.globalData.openid }, function (res) {
                    app.globalData.loginInfo = res.data;
                    app.myMethod.loading();
                    console.log(JSON.stringify(res.data));
                    if(res.data.phone.length == 11 && res.data.client_phone==res.data.phone && res.data.is_manage==1){  //对比电话和管理员身份
                      util.again_login();
                    };
                    that.setData({
                      loginInfo: res.data,
                      status: 1,
                      client_is_store:res.data.client_is_store,  //是否有库(是否有需求单)
                      good_dir_set:res.data.good_dir_set,  //2:总部目录
                      template_id:res.data.template_id,  //大于0时有模板
                      group_id: res.data.group_id,  //是否绑定了集团码
                      group_name:res.data.group_name,  //集团名称
                      type_level:res.data.type_level    
                    });
                    app.globalData.set_receved=res.data.set_receved;  //是否设置收货 0否1是 
                    app.globalData.group_id = res.data.group_id;
                    app.AppHttp("api/Client/joinClient", { openid: app.globalData.openid, search_code: res.data.search_code }, function (res) {
                      console.log(JSON.stringify(res.data));
                      if(res.data.status==-1){
                        if (app.globalData.loginInfo.phone.length!=11) {
                          // 未注册手机号
                          step=1;
                          app.globalData.step=1;
                          that.scene_win(null,1);
                        }else if (app.globalData.loginInfo.phone.length==11) {
                          // 还没有门店
                          step=2;
                          app.globalData.step=2;
                          that.scene_win(null,2);
                          console.log(step);
                        }
                      }else if(res.data.data.apply_status==1){
                        step=3;
                        app.globalData.step=3;
                        //正常账号才显示底部导航
                        if(app.globalData.loginInfo.client_is_store<0 && app.globalData.loginInfo.type_level==0 || app.globalData.loginInfo.client_is_store==0){      
                          app.globalData.list =  averageUser;     //无需求单和库存
                        }else if(app.globalData.loginInfo.client_is_store<0 && app.globalData.loginInfo.type_level==1 || app.globalData.loginInfo.client_is_store==1){
                          app.globalData.list =  dealers;            //有需求单和库存 
                        }; 
                        app.globalData.type_level = app.globalData.loginInfo.type_level;   
                        if (typeof that.getTabBar === 'function' && that.getTabBar()) {
                          that.getTabBar().setData({
                            type_level:app.globalData.loginInfo.type_level,
                            is_manage:app.globalData.loginInfo.is_manage,  //是否为管理员
                            ischarge:app.globalData.loginInfo.ischarge,  //库管 是1 否0
                            is_purchase_check:app.globalData.loginInfo.is_purchase_check,  //采购单审核  是1 否0
                            selected: 0,
                            list: app.globalData.list
                          })
                        };
                        if(app.globalData.loginInfo.is_manage==2){  //正常用户（仅管理员可扫码成功）
                          that.scene_win(that.data.loginInfo.id,3);
                        };
                        if(that.data.good_dir_set<1){  //个体户
                          if(that.data.type_level==0){
                            that.getSupplierList(app.globalData.openid); 
                          }else if(that.data.type_level==1){
                            that.setData({
                              step:3,   //防止.gouwu-img-box坐标获取不到
                              supername: app.globalData.loginInfo.client_abbre
                            });    
                            if(that.data.template_id>0){               
                              that.setData({
                                isShowSuperList:3
                              });
                              mySuperFirstShop.open_onload(left_height,coll_right_h); // 通过实例调用组件事件
                            }else{
                              that.setData({
                                load_num:0
                              });
                            }
                          };
                        }else if(that.data.good_dir_set==1){    //供应商列表
                          that.getSupplierList(app.globalData.openid); 
                        }else if(that.data.good_dir_set>=2){   //商品库
                          that.setData({
                            supername: app.globalData.loginInfo.client_abbre,
                            step:3  //防止.gouwu-img-box坐标获取不到
                          });    
                          if(that.data.template_id>0){
                            that.setData({
                              isShowSuperList:3
                            });
                            mySuperFirstShop.open_onload(left_height,coll_right_h); // 通过实例调用组件事件
                          }else{
                            that.setData({
                              load_num:0
                            });
                          }
                        }
                      }else if(res.data.data.apply_status!=1){
                        if (that.data.loginInfo.phone.length !=11) {
                          step=1;
                          // 未注册手机号
                          app.globalData.step=1;
                          that.scene_win(null,1);
                        }else if (that.data.loginInfo.phone.length == 11) {
                          // 还没有门店
                          step=2;
                          app.globalData.step=2;
                          that.scene_win(null,2);
                        };
                        app.userStatus();
                      }; 
                      if(step<3){
                        app.globalData.list=[];
                        that.setData({
                          isShowSuperList:0,
                          load_num:0
                        });
                        that.getTabBar().setData({
                          selected: 0,
                          list: app.globalData.list
                        })
                      }
                      that.setData({
                        step:step,
                        apply_status: res.data.data.apply_status
                      });
                    })
                  });         
                } else {
                  app.globalData.loginInfo={
                    client_abbre:'',
                    good_dir_set:'',
                    client_is_store:'',
                    purchase_type:''
                  };  //添加合作时保证交互流程
                  that.scene_win(null,0);
                  app.globalData.step=0;
                  app.globalData.list=[];
                  that.setData({
                    load_num:0,
                    isShowSuperList:0,
                    step:0
                  });
                }
              })
            });
          }
        });
      }
    });
  },
  // 扫码弹窗
  scene_win:function(client_id,step){   
    var that = this;
    var obj=wx.getEnterOptionsSync();
    var scene;
    var storeNo; 
    if((obj.scene==1047 || obj.scene==1048 || obj.scene==1049) && obj.query.scene || that.data.type=='super'){  //扫码或分享店铺
      if(that.data.call_load==1){  //扫码只能创建门店
        if(obj.scene==1047 || obj.scene==1048 || obj.scene==1049){ //小程序码进
          scene=obj.scene;
          storeNo = obj.query.scene;
          storeNo = storeNo.split('id%3D')[1];  
        }else if(that.data.type=='super'){
          storeNo=that.data.share_super_id;
        }else{
          return;
        };    
        app.AppHttp("api/Client/getSymbiosis", {supplier_id:storeNo,client_id:client_id}, function (res) {
          console.log(JSON.stringify(res.data));
          that.setData({
            scene:scene,
            storeNo_super_id:storeNo,
            sao_super:res.data.data.supplier_info
          });
          that.in_cur_door();
          that.setData({
            call_load:0  //阻止再次调用此接口
          });
        });
      };
    }else{
      that.setData({
        scene:obj.scene
      });
    }; 
  },
  // 供应商详情
  supperdetail:function(){
    var that = this;
    app.AppHttp('api/Client/supperDetail', {  
      openid: app.globalData.openid,
      id: that.data.group_id
    }, function (res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        supper_detail: res.data.data
      });
    })
  },
  // 微信授权
  getUserProfile:function(e){
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res);
        var userInfo=res.userInfo;
        var that = this;
        wx.login({
          success: function (ress) {
            console.log(userInfo);
            var data = {
              appId: app.globalData.appId,
              secret: app.globalData.secret,
              code: ress.code,
              head_portrait: userInfo.avatarUrl,
              avatarUrl: userInfo.avatarUrl,
              sex: userInfo.gender,
              country: userInfo.country,
              nickname: userInfo.nickName,
              dk_type:0,
            };
            app.AppHttp('api/Client/ClientPersonalAuth', data, function (res) {
              if (res.data.status == 1) {
                wx.showToast({
                  title: res.data.msg,
                  success: function () {
                    app.globalData.step=1;
                    that.setData({
                      step:1
                    });
                    setTimeout(function () {
                      that.scene_win(null,1);
                      if(app.globalData.unionid==undefined){ 
                        // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
                        wx.getUserInfo({
                          success: res => {
                            // 可以将 res 发送给后台解码出 unionId
                            console.log(res);
                            encryptedData=res.encryptedData;
                            iv=res.iv;
                            app.globalData.userInfo = res.userInfo
                            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
                            // 所以此处加入 callback 以防止这种情况
                            var sdata = {
                              appId: app.globalData.appId,
                              sessionKey:app.globalData.session_key,
                              encryptedData:encryptedData,
                              iv:iv
                            };
                            app.AppHttp('api/Client/DataDecryption',sdata, function (res) {
                              console.log(JSON.stringify(res.data));
                                app.globalData.unionid = res.data.unionId;
                                app.AppHttp('api/Client/updateUnionid',{openid:app.globalData.openid,unionid:res.data.unionId}, function (res) {
                                  console.log(JSON.stringify(res.data));  
                                });           
                            });
                          }
                        });
                      };
                    })
                  }
                }, 2000);
              } else {
                wx.showModal({
                  title: '授权异常'
                })
              }
            });
          }
        });
      }
    });
  },
  // 获取手机号
  getPhoneNumber:function(e){
    var that = this;
    if(e.detail.errMsg == "getPhoneNumber:ok"){  //用户点击了允许
      var iscj=e.currentTarget.dataset.iscj;
      wx.login({
        success:function(res){
          console.log(res);
          var data = {
            appId: app.globalData.appId,
            sessionKey:app.globalData.session_key,
            encryptedData:e.detail.encryptedData,
            iv:e.detail.iv
          };
          app.AppHttp('api/Client/DataDecryption',data, function (res) {
            console.log(JSON.stringify(res.data));
            if(app.globalData.unionid==undefined){   //没有unionId，更新unionId
              app.globalData.unionid = res.data.unionId;
              console.log(res.data.phoneNumber);
              app.AppHttp('api/Client/updateUnionid',{openid:app.globalData.openid,unionid:res.data.unionId}, function (res) {
                console.log(JSON.stringify(res.data));  
              });
            };
            if(iscj=='cj'){  //创建新门店
              that.bind_and_cre(res.data.phoneNumber,'create');
            }else if(iscj=='add'){  //加入已有门店(仅绑定手机);
              that.bind_and_cre(res.data.phoneNumber,'join');
            };      
          });
        }
      })
    }else{
      console.log('已经拒绝');
    };
  },
  // 绑定手机并创建新门店(或仅绑定手机)
  bind_and_cre:function(phone,join_type){
    var that = this;
    app.AppHttp('api/Client/WechatUserBindSupplier',{openid:app.globalData.openid,phone:phone,join_type:'join'}, function (res) {
      console.log(JSON.stringify(res.data));
      wx.showToast({
        title: res.data.msg
      }); 
      if(join_type=='create'){
        app.globalData.step=2;
        that.setData({
          step:2,
        });
        that.toCreateSuper();
      }else{
        app.globalData.step=2;
        that.setData({
          step:2
        });
        that.add_md();
      };      
    });
  },
  // 创建新门店
  create_md:function(){
    var that = this;
    that.toCreateSuper();
    return;
    app.AppHttp('api/Client/CreateClient',{
      openid: app.globalData.openid,
      client_abbre:that.data.loginInfo.nickname,
      username:that.data.loginInfo.nickname,
      account_number:''
    }, function (res) {
      console.log(JSON.stringify(res.data));
      wx.showToast({
        title: res.data.msg
      }); 
      that.user_onLoad();            
    });     
  },
  toCreateSuper:function(){
    wx.navigateTo({   
      url:'/group_space/pages/CreateSuper/CreateSuper'
    });
  },
  add_md:function(){
    wx.navigateTo({    //绑定门店
      url:'/group_space/pages/bind_group/bind_group'
    })
  },
  // 添加供应商接口
  conf_AddsuperOK:function(){
    var that = this;
    if(that.data.loginInfo.id){  //id存在 
      that.conf_AddsuperOk_perf(that.data.loginInfo.id);
    }else{
      app.AppHttp("api/Client/basicInfo", { openid: app.globalData.openid }, function (res) {
        console.log(JSON.stringify(res.data));
        that.conf_AddsuperOk_perf(res.data.id);
      });
    };
  },
  // 搜索供应商名称
  searSuperInput:function(e){
    this.setData({
      searSuperName:e.detail.value
    });
    this.getSupplierList(app.globalData.openid);
  },
  searSuper:function(){
    this.getSupplierList(app.globalData.openid);
  },
  searSuperConf:function(){
    this.getSupplierList(app.globalData.openid);
  },
  delsuper:function(){
    this.setData({
      searSuperName:''
    });
    this.getSupplierList(app.globalData.openid);
  },
  // 供应商列表
  getSupplierList: function (openid) {
    var that = this;
    wx.showLoading({
      title:'加载中',
    });
    app.AppHttp("api/Goods/getSupplierList", { 
        openid: openid, 
        type: 0
      }, function (res) {
        console.log(JSON.stringify(res.data));
        var rightDatas=[];
        if(res.data.status!=-1){
          var loginInfo=that.data.loginInfo;
          if(loginInfo.hq_is_store==1){
            let logo;
            if(loginInfo.brand_logo){
              if(loginInfo.brand_logo.substring(0,7)=='/upload'){
                logo='http://www.xiaobangcai.com/'+loginInfo.brand_logo
              }else{
                logo=loginInfo.brand_logo
              };
            }else{
              if(loginInfo.supplier_logo.substring(0,7)=='/upload'){
                logo='http://www.xiaobangcai.com/'+loginInfo.supplier_logo
              }else{
                logo=loginInfo.supplier_logo
              };
            }
            rightDatas[0]={
              id:loginInfo.group_id,
              logo:logo,
              supplier_id:loginInfo.group_id,
              business_id:loginInfo.group_id,
              status:1,
              company_name:loginInfo.group_name,
              supplier_type:3,
              is_zicai_supplier:0
            }    
            rightDatas=rightDatas.concat(res.data.data[0])
            console.log(rightDatas)
          }else{
            rightDatas=res.data.data[0];
          }
        }
        rightDatas = rightDatas.filter(function (item) {   
          return item.company_name  
        });
        rightDatas = rightDatas.map(function (item) {   
          if(item.company_name.indexOf(that.data.searSuperName)!=-1){
            item.isSear=true
          };
          return item  
        });
        that.setData({
          load_num:0,
          statusmsg:res.data.msg,
          rightDatas: rightDatas,
          renstatus: res.data.status
        });
        if(rightDatas.length==1 && rightDatas[0].status==1){
          let options={
            id:rightDatas[0].id,
            super_info:JSON.stringify(rightDatas[0])
          }
          that.setData({
            share_name:rightDatas[0].company_name,
            isShowSuperList:1  //1显示商品库组件
          })
          mySuperShop.open_onload(options,left_height,coll_right_h,z_scroH); // 通过实例调用组件事件
        }else if(rightDatas.length==0){
          that.setData({
            isShowSuperList:0 //0初始,无供应商
          })
        }else{
          that.setData({
            isShowSuperList:2 //2显示供应商列表
          })
        }
        wx.hideLoading();
    });
  },
  noneEnoughPeople(){
    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady(){
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.hideShareMenu();//隐藏转发分享按钮
    if (typeof that.getTabBar === 'function' && that.getTabBar()) {
      that.getTabBar().setData({
        selected: 0,
        list: app.globalData.list
      })
    };  
    if(this.data.load_num==0){
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 0
      });
      if(app.globalData.CreateSuper==1){
        that.setData({
          call_load:1
        });
        app.globalData.CreateSuper='';
      };
      that.setData({
        ishide:false,
        page:1,
        load:'加载中...'
      }); 
      that.user_onLoad();    
    };  
    app.globalData.dingdan_show = 1; //切换导航时，返回订单页需要刷新
    app.globalData.caigou_shua=1;  
  },
  onPageScroll:function(e){
    var scrollTop = parseInt(e.scrollTop); //滚动条距离顶部高度;
    var isGun = scrollTop >= z_scroH ? true : false;
    if (this.data.gun === isGun) {
      return false;
    };
    this.setData({
      gun: isGun
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      ishide:true
    });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if(this._observer) this._observer.disconnect();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    app.globalData.list=[];
    wx.showLoading({
      title:'加载中...',
    });
    this.user_onLoad();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {  
    return {
      title:this.data.share_name+'的线上商城，邀请您下单！',
      path: 'pages/shangpin/shangpin?id='+this.data.rightDatas[0].id+'&type='+'super',
      imageUrl:'http://www.xiaobangcai.com/upload/smallprogram/mall_card1.jpg'
    }; 
  }
})